# encoding: UTF-8

class Admin::SessionsController < ApplicationController

  def new
    unless current_user
      render :layout => false
    else
      redirect_to grids_path
    end
  end

  def create
    if user = User.authenticate(params[:session][:login], params[:session][:passwd])
      session[:user_id] = user.id
      #flash[:notice] = "welcome, #{user.login}"
      flash[:notice] = 'welcome!'
      redirect_to grids_path
    else
      flash[:notice] = "the username or password is not corrected!"
      redirect_to signin_url
    end 
  end

  def destory
    session[:user_id] = nil
    redirect_to signin_url, :notice => 'signout out successfully!'
  end

end
